//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package cn.zyjblogs.starter.common.entity.response;

/**
 * @author zhuyijun
 */
public class ResponseResult {
    private static final int ZERO_DATA_TOTAL = 0;
    private static final int ONE_DATA_TOTAL = 1;

    private ResponseResult() {
    }

    public static ResponseObject<Object> success() {
        return success(0L, (Object) null);
    }

    public static <T> ResponseObject<T> success(T data) {
        return success(1L, data);
    }

    public static <T> ResponseObject<T> success(T data, String msg) {
        return success(1L, data, msg);
    }

    public static <T> ResponseObject<T> success(long total, T data) {
        return ResponseObject.<T>builder().code(HttpCode.OK.value()).msg(HttpCode.OK.getReasonPhrase()).count(total).data(data).timestamp(System.currentTimeMillis()).build();
    }

    public static <T> ResponseObject<T> success(long total, T data, String msg) {
        return ResponseObject.<T>builder().code(HttpCode.OK.value()).msg(msg).count(total).data(data).timestamp(System.currentTimeMillis()).build();
    }

    public static <T> ResponseObject<T> error(HttpCode responseCode, String errorMsg) {
        return error(responseCode, errorMsg, 0L, null);
    }

    public static <T> ResponseObject<T> error(HttpCode responseCode, String errorMsg, T data) {
        return error(responseCode, errorMsg, 1L, data);
    }

    public static <T> ResponseObject<T> error(HttpCode responseCode, String errorMsg, long total, T data) {
        if (responseCode.value() == HttpCode.OK.value()) {
            throw new IllegalArgumentException("ResponseResult.error方法中的responseCode参数不能是ResponseCode.REQUEST_SUCCESS");
        } else {
            return ResponseObject.<T>builder().code(responseCode.value()).msg(errorMsg == null ? responseCode.getReasonPhrase() : errorMsg).count(total).data(data).timestamp(System.currentTimeMillis()).build();
        }
    }
}
